<!--
 * @Description: 首页 - 菜品和桌台管理
 * @Author: duan_shuangjun 丶
 * @Date: 2025-08-20 20:24:07
 * @LastEditTime: 2025-09-06 23:46:09
-->
<template>
  <div>
    <div class="content-wrap">
      <div class="right-box">
        <!-- 桌台相关的组件 -->
        <DesktopModules @selectTable="selectTable" />
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, watch } from 'vue'
import { useUserStore } from '@/stores/user'
import FoodModules from './components/Food/Index.vue'
import DesktopModules from './components/Desktop/Index.vue'
import { LocalStorage } from '@/utils/storage'
import { fetchDeskDetail } from '@/api/desktop'
import { ElMessage } from 'element-plus'
import { useRouter } from 'vue-router'

const router = useRouter()

// 当前选中的桌台详情ID
const currentDeskDetail = ref(null)
// 当前桌台详情数据
const deskDetailData = ref<any>(null)
const userStore = useUserStore()
// 加载状态
const loading = ref(false)

const selectTable = (data: any) => {
  console.log('选中桌台:', data)
  // currentDeskDetail.value = data?.recordInfo?.id
  router.push(`/home/food/${data?.recordInfo?.id}`)
}

onMounted(() => {
  // 首页相关的页面不执行此操作
  const currentRoutePath = window.location.pathname
  if (
    ![
      '/',
      '/orderDish/index',
      '/orderDish/cuisinePractice',
      '/orderDish/cuisineTaste',
      '/orderDish/cuisinePosition',
      '/orderDish/SideDish',
      '/home/preconsolidation',
      '/home/businessStatement'
    ].includes(currentRoutePath)
  ) {
    // 清空本地数据
    LocalStorage.remove('selectCurrentDeskData')
    LocalStorage.remove('currentDeskDetail')
    LocalStorage.remove('SELECT_CURRENT_FOOD')
    // 重置左侧选中的菜品索引
    LocalStorage.remove('selectFoodActiveIndex')
  }

  // 获取当前店铺开班状态
  // fetchDeskWorkStatus()
  // fetchFirstLoginLocalKeepData()
})

// 获取当前店铺开班状态
// const fetchDeskWorkStatus = async () => {
//   try {
//     // TODO: 实现获取桌台工作状态的逻辑
//     console.log('获取桌台工作状态')
//   } catch (error) {
//     console.error('获取桌台工作状态失败:', error)
//   }
// }

// 获取首次登录本地保持数据
// const fetchFirstLoginLocalKeepData = async () => {
//   try {
//     // TODO: 实现获取首次登录本地保持数据的逻辑
//     console.log('获取首次登录本地保持数据')
//   } catch (error) {
//     console.error('获取首次登录本地保持数据失败:', error)
//   }
// }
</script>

<style lang="scss" scoped>
.content-wrap {
  display: flex;
  align-items: flex-start;
  .left-box {
    margin-right: 30px;
  }
  .right-box {
    // flex: 1;
    width: 100%;
  }
}
</style>
